import java.sql.*;

public class Demo {
    public static void main(String[] args) throws Exception {
        Class.forName("org.apache.calcite.avatica.remote.Driver");

        final Connection con =
                DriverManager.getConnection("jdbc:avatica:remote:url=http://node01:8888/druid/v2/sql/avatica/");

        String sql =
                "SELECT user, sum(views) as view_count FROM \"metrics-kafka\" GROUP BY 1 ORDER BY 1";
        final Statement statement = con.createStatement();
        final ResultSet resultSet = statement.executeQuery(sql);

        while (resultSet.next()) {

            String user = resultSet.getString("user");
            long view_count = resultSet.getLong("view_count");
            System.out.println(user + " -> " + view_count);
        }
        resultSet.close();
        statement.close();
        con.close();
    }
}
